package schema

import (
	"time"

	"lianzi_gos/pkg/util"
)

// 实勘， 带客到访 追踪表
type Record struct {
	ID          string    `json:"id" gorm:"size:20;primarykey;"`                        // Unique ID
	Name        string    `json:"name" gorm:"size:32;index"`                            // 名称
	Phone       string    `json:"phone" gorm:"size:32;index"`                           // 电话
	GID         string    `json:"gid" gorm:"size:32;index"`                             // 电话 客户ID
	Types       int       `json:"types" gorm:"index"`                                   // 1 实勘 2带客
	Img         string    `json:"img" gorm:"size:1000;index"`                           // 图片
	Source      int64     `json:"source" gorm:"index;default:1;comment:'1我要买  2客户渠道';"` //  来源
	Description string    `json:"description" gorm:"size:1024"`                         // Details about dictionary
	Status      string    `json:"status" gorm:"size:20;index;default:enabled"`          // Status of dictionary (disabled, enabled)
	CreatedAt   time.Time `json:"created_at" gorm:"index;"`                             // Create time
	UpdatedAt   time.Time `json:"updated_at" gorm:"index;"`                             // Update time
}

// Defining the query parameters for the `Record` struct.
type RecordQueryParam struct {
	util.PaginationParam
	GID    string `form:"gid"`
	Types  int    `form:"types"`
	Source int64  `form:"source"`
	Status string `form:"-"`
}

// Defining the query options for the `Record` struct.
type RecordQueryOptions struct {
	util.QueryOptions
}

// Defining the query result for the `Record` struct.
type RecordQueryResult struct {
	Data       Records
	PageResult *util.PaginationResult
}

// Defining the slice of `Record` struct.
type Records []*Record

// Defining the data structure for creating a `Record` struct.
type RecordForm struct {
	Name        string `json:"name"`                          // 名称
	Phone       string `json:"phone"`                         // 电话
	Source      int64  `json:"source" `                       // 电话
	Img         string `json:"img"`                           // 照片
	GID         string `json:"gid" binding:"required,max=32"` //  商品
	Types       int    `json:"types"`                         // 1 实勘 2带客 3 3 客户跟进
	Description string `json:"description"`                   // Details about dictionary
}

// A validation function for the `RecordForm` struct.
func (a *RecordForm) Validate() error {
	return nil
}

// Convert `RecordForm` to `Record` object.
func (a *RecordForm) FillTo(record *Record) error {
	record.Name = a.Name
	record.Phone = a.Phone
	record.Img = a.Img
	record.Types = a.Types
	record.GID = a.GID
	record.Source = a.Source
	record.Description = a.Description
	record.Status = "enabled"
	return nil
}
